class OurClass { OtherObject *a; OtherObject *b; public: OurClass(const OtherObject &aRef, const OtherObject &bRef): a(new OtherObject(aRef)), b(new OtherObject(bRef)) {}; ~OurClass() { delete a; delete b; }; .... };
Alternative:
OurClass(const OtherObject &aRef, const OtherObject &bRef): a(0), b(0) { try { a = new OtherObject(aRef); b = new OtherObject(bRef); } catch (...) { delete a; delete b; } };